package com.study.pool1;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

/**
 * @author zhuzi
 * 2022/8/28 08:58
 */
public class MyPoolableObjectFactory extends BasePooledObjectFactory<Resource> {
    /**
     * 创建一个实例对象
     */
    @Override
    public Resource create() throws Exception {
        return new Resource();
    }

    /**
     * 包裹创建对象，返回一个pooledobject
     *
     * @param resource
     * @return
     */
    @Override
    public PooledObject<Resource> wrap(Resource resource) {
        return new DefaultPooledObject<>(resource);
    }
}
